﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;

namespace ui
{
    public class _frame : _control
    {
        string _text = "";
        Color _BorderColor = Color.Black;
        Color _BackgroundColor = Color.White;
        int _Margin = 2;

        public _frame()
            : base()
        {
            type = ControlTypes.Frame;
        }

        public override void setup(PictureBox p)
        {
            base.setup(p);
        }

        [Category("Data"), Description("Caption")]
        public string Caption
        {
            get { return _text; }
            set { _text = value; if(pic!=null) pic.Invalidate(); }
        }

        [Category("Appearance"), Description("Margin")]
        public int Margin
        {
            get { return _Margin; }
            set { _Margin = value; if (pic != null)  pic.Invalidate(); }
        }

        [XmlElement(Type = typeof(_xmlcolor))]
        [Category("Appearance"), Description("Border Color")]
        public Color BorderColor
        {
            get { return _BorderColor; }
            set { _BorderColor = value; if (pic != null) pic.Invalidate(); }
        }

        [XmlElement(Type = typeof(_xmlcolor))]
        [Category("Appearance"), Description("Background Color")]
        public Color BackgroundColor
        {
            get { return _BackgroundColor; }
            set { _BackgroundColor = value; if (pic != null)  pic.Invalidate(); }
        }

        public override void render(object sender, PaintEventArgs e)
        {
            g = e.Graphics;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;

            SizeF s = g.MeasureString(Caption, parent.mainFont);
            Brush fill = new SolidBrush(BackgroundColor);
            Brush fill2 = new SolidBrush(BorderColor);

            g.FillRectangle(fill, new Rectangle(0, 0, width - 1, height- 1));
            if (Caption != "")
            {
                g.FillRectangle(fill2, new Rectangle(0, 0, width - 1, 12));
                g.DrawString(Caption, parent.mainFont, new SolidBrush(BackgroundColor), 0, 0);
            }
            g.DrawRectangle(new Pen(BorderColor), new Rectangle(0, 0, width - 1, height - 1));

            base.render(sender, e);
        }
    }
}
